<template> 
<!-- 充值余额 -->
    <div class="rechargecontent">
        <div class="figure">
            <img src="https://oss-frakiss.oss-cn-chengdu.aliyuncs.com/icon/mini_images/2_4.png" class="figure_bgImg" alt="">
            <div class="figure_banner">
                <div class="figure_banner_img">
                    <img src="https://oss-frakiss.oss-cn-chengdu.aliyuncs.com/icon/mini_images/2_3.png" alt="">
                </div>
                <div class="figure_banner_figure">总余额</div>
                <div class="figure_banner_number">￥{{userBasicInfo.balance?userBasicInfo.balance:'0.00'}}</div>
            </div>
        </div>
        <block v-if="getRechargeList.length">
            <div class="box" v-for="(item,index) in getRechargeList" :key="index">
                <div class="box_icon">
                    <img :src="item.cover" alt="">
                </div>
                <div class="box_banner">
                    <div class="box_banner_ins">{{item.name}}</div>
                    <div class="box_banner_text">
                        ￥{{item.balance}}
                    </div>
                </div>
            </div>
        </block>
        <ListEmpty v-else />

    </div>
</template>

<script lang="ts">
import store from '@/store';

import ListEmpty from '@/components/list/listEmpty.vue';
import {
    api,
} from '@/lib/api';

import { Component, Vue } from 'vue-property-decorator';
import { ROUTE_NAME } from '@/lib/constant';
import { Route } from 'vue-router';
import { EMPTY_LIST } from '@/lib/constant';

Component.registerHooks([
    'beforeRouteEnter',
]);

@Component({
    name: 'rechargeList',
    components: {
        ListEmpty
    }
})

export default class rechargeList extends Vue {

    /** 用户基础信息 */
    public get userBasicInfo() {
        return store.state.user.basicInfo;
    }

    /** 订单列表 */
    public get wrap() {
        return store.state.shop.rechargeList['null'] || {
            list: [],
            loaded: false,
            req: false,
        };
    }
    public get getRechargeList(){
        return this.wrap.list;
    }    
    public async onReachBottom() {
        await store.dispatch('shop/getRechargeList', {
            offset: this.getRechargeList.length,
            count: 10,
            forceUpdate:false
        });
    }
    async onPullDownRefresh() {
        store.commit('utils/startPulldown');
        await store.dispatch('shop/getRechargeList', {
            offset: 0,
            count: 10,
            forceUpdate: true
        });
        store.commit('utils/endPulldown');
    }
    public async beforeRouteEnter(to: Route, from: Route, next: any) {
        store.commit('utils/startRequest');
        await Promise.all([
            store.dispatch('shop/getRechargeList', {
                offset: 0,
                count: 10,
                forceUpdate: true
            }),
        ]);
        store.commit('utils/endRequest');
        next();
    }

    public async created() {
        window.addEventListener('reachbottom', this.onReachBottom);
        window.addEventListener('pulldownrefresh', this.onPullDownRefresh);
    }
    public beforeDestroy() {
        window.removeEventListener('reachbottom', this.onReachBottom);
        window.removeEventListener('pulldownrefresh', this.onPullDownRefresh);
    }

    
}
</script>
<style lang="less">
.rechargecontent{
    width: 100%;
    min-height: 100vh;
    // overflow: hidden;
    // overflow-y: scroll;
    background-color: #F8F8F8;
    .figure{
        position: relative;
        width: 92%;
        text-align: center;
        height: 260rpx;
        margin: 0rpx auto;
        .figure_bgImg{
            position: absolute;
            left: 0;
            top: 0;
            z-index: 0;
            width: 100%;
            height: 260rpx;
            z-index:0;
        }
        .figure_banner{
            position: relative;
            width: 90%;
            border-radius: 30rpx 100rpx 30rpx 30rpx;
            // background-color: #FF929D;
            color: #ffffff;
            margin: auto;
            padding-top: 20rpx;
            z-index: 99;
            
            .figure_banner_img{
                width: 40rpx;
                height: 40rpx;
                z-index: 99;
                margin: 10rpx auto;
                img{
                    width: 100%;
                    height: 100%;
                }
            }
            .figure_banner_figure{
                font-size: 20rpx;
            }
            .figure_banner_number{
                font-size: 40rpx;
            }
        }   
    }  
    .box{
        width: 92%;
        line-height: 120rpx;
        display: flex;
        // justify-content: space-around;
        justify-content: space-evenly;
        background-color: #ffffff;
        border-radius: 10rpx;
        padding: 10rpx 0rpx;
        margin: 0rpx auto;
        .box_icon{
            width: 90rpx;
            height: 90rpx;
            img{
                width: 90rpx;
                height: 90rpx;
                border-radius: 30rpx;
                background-color: #E6E6E6;
            }
        }
        .box_banner{
            width: 82%;
            height: 120rpx;
            line-height: 120rpx;
            display: flex;
            justify-content: space-around;
            border-bottom: 1rpx solid #cccccc;
            .box_banner_ins{
                width: 68%;
                font-size: 30rpx;
                color: #000;
                overflow: hidden;
                text-overflow:ellipsis;
                white-space: nowrap;
            }
            .box_banner_text{
                width: 30%;
                line-height: 120rpx;
                font-size: 32rpx;
                text-align: right;
                font-weight: 600;
                color: crimson;
            }
        }
    }
        
}
</style>
